package com.ihd.ihardware.view.enter.viewModel;

import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.support.annotation.NonNull;

import com.ihd.ihardware.view.enter.model.LoginRepository;

import java.io.File;

public class RegistViewModel extends AndroidViewModel {

    private LoginRepository mLoginRepository;

    public RegistViewModel(@NonNull Application application) {
        super(application);
    }

    public void sendVerifySms(String phone, String type) {
        if (mLoginRepository == null)
            mLoginRepository = new LoginRepository();
        mLoginRepository.sendVerifySms(phone, type);
    }

    public void regist(String phone, String password, String code) {
        if (mLoginRepository == null)
            mLoginRepository = new LoginRepository();
        mLoginRepository.regist(phone, password, code);
    }

    public void updateHead(File f) {
        if (mLoginRepository == null)
            mLoginRepository = new LoginRepository();
        mLoginRepository.updateHead(f);
    }

    public void updateInfo(String avatar, String nickName, String sex, String birthday, String height, String weight) {
        if (mLoginRepository == null)
            mLoginRepository = new LoginRepository();
        mLoginRepository.updateInfo(avatar, nickName, sex, birthday, height, weight);
    }

    public void dream(String weight) {
        if (mLoginRepository == null)
            mLoginRepository = new LoginRepository();
        mLoginRepository.dream(weight);
    }

    public void getUserInfo() {
        if (mLoginRepository == null)
            mLoginRepository = new LoginRepository();
        mLoginRepository.getUserInfo();
    }

    public void wxLogin(String code) {
        if (mLoginRepository == null)
            mLoginRepository = new LoginRepository();
        mLoginRepository.wxLogin(code);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        if (null != mLoginRepository) {
            mLoginRepository.onDestroy();
            mLoginRepository = null;
        }
    }
}
